package templateMethod;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*************************************************************
 *
 * 这是我们的咖啡类，用来煮咖啡
 *
 **********************************************************/
public class TeaWithHook extends CaffeineVeverageWithHook{
    //这是我们的咖啡冲泡法，直接取自训练手册


    /**
     * 以下每个方法都实现了算法中的一个步骤：著沸水/冲泡咖啡/把咖啡倒进杯子/加糖和奶
     */
    public void brew(){
        System.out.println("Steeping the tea");

    }
    //这个方法是泡茶专有
    public void addCondiments(){
        System.out.println("adding Lemon");
    }


    //=============================================


    @Override
    boolean customerWantsCondiments() {
        String answer = getUserInput();

        return answer.toLowerCase().startsWith("y");
    }

    private String getUserInput() {

        String answer = null;

        System.out.println("Would you like Lemon with your tea (y/n)?");

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        try {
            answer = in.readLine();

        } catch (IOException e) {
            System.err.println("IO error trying to read your answer");
        }
        if (answer == null){
            return "no";
        }
        return answer;
    }
}
